#include "Util.h"

#include <stdio.h>
#include <iostream>
#include <limits.h>
#include <math.h>

Util::Util() {

}

Util::~Util() {
}

char* Util::stringToCharAst(string value){
	char *cstr = new char[value.length() + 1];
	strcpy(cstr, value.c_str());
	return cstr;
}

string Util::intToString(int value) {
	std::stringstream out;
	out << value;
	return out.str();
}

string Util::uIntToString(unsigned int value) {
	std::stringstream out;
	out << value;
	return out.str();
}


int Util::stringToInt(string str) {
	stringstream ss(str);
	int n;
	ss >> n;
	return n;
}

unsigned int Util::stringToUint(string str) {
	stringstream ss(str);
	unsigned int n;
	ss >> n;
	return n;
}


unsigned int Util::charAstToUInt(const char *cad){
    unsigned int num = 0;
    int tam  = strlen(cad);  /* Longitud de la cadena recibida */
    int digito;
    int i;
    for (i = tam ; i > 0; --i) {
        digito = (unsigned int) (cad[i - 1] - 48);
        num += digito * pow(10.0, tam - i);
    }
    return num;
}

int Util::toInt(string str) {
	stringstream ss(str);
	int n;
	ss >> n;
	return n;
}

char* Util::intToCharAst(int value){
	return Util::stringToCharAst(Util::intToString(value));
}





